<template>
  <div class="container">
    <div class="header">
      <div class="core">
        <img :src="userInfo.avatar" alt="" />
        <p>{{ userInfo.username }}</p>
      </div>
    </div>
    <div class="myasset">
      <p class="title">我的资产</p>
      <div class="asset">
        <div class="assetItem">
          <van-badge dot>
            <p class="hot">￥<span>0</span></p>
          </van-badge>
          <p>余额</p>
        </div>
        <div class="assetItem">
          <p>￥<span>0</span></p>
          <p>红包</p>
        </div>
        <div class="assetItem">
          <p>￥<span>0</span></p>
          <p>优惠券</p>
        </div>
        <div class="assetItem">
          <p>￥<span>0</span></p>
          <p>积分</p>
        </div>
        <div class="assetItem">
          <p>￥<span>0</span></p>
          <p>礼品卡</p>
        </div>
      </div>
    </div>
    <div class="table">
      <div class="table_item">
        <div class="core">
          <div class="icon"><van-icon name="balance-list-o" size="25" /></div>
          <div class="content">我的订单</div>
        </div>
      </div>
      <div class="table_item">
        <div class="core">
          <div class="icon"><van-icon name="balance-list-o" size="25" /></div>
          <div class="content">我的订单</div>
        </div>
      </div>
      <div class="table_item">
        <div class="core">
          <div class="icon"><van-icon name="balance-list-o" size="25" /></div>
          <div class="content">我的订单</div>
        </div>
      </div>
      <div class="table_item">
        <div class="core">
          <div class="icon"><van-icon name="balance-list-o" size="25" /></div>
          <div class="content">我的订单</div>
        </div>
      </div>
      <div class="table_item">
        <div class="core">
          <div class="icon"><van-icon name="balance-list-o" size="25" /></div>
          <div class="content">我的订单</div>
        </div>
      </div>
    </div>
    <div class="logout" @click="logout">退出登录</div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/store/user.ts'
const userstore = useUserStore()

// 渲染用户头像和名称
const userInfo = ref({
  avatar:
    'https://tse3-mm.cn.bing.net/th/id/OIP-C.Skv8xm2IOwEoZ95t_fPFJQHaHa?w=165&h=180&c=7&r=0&o=5&dpr=1.3&pid=1.7',
  username: userstore.userInfo.name || '请登录'
})

const router = useRouter()

// 退出登录
const logout = async () => {
  const res = await userstore.logOut()
  if (res) {
    router.push('/login')
  }
}
</script>

<script lang="ts">
export default {
  name: 'MyIndex'
}
</script>

<style scoped lang="less">
.container {
  box-sizing: border-box;
  width: 100%;
  background-color: #eee;
  font-size: 18px;
  p {
    margin: 0;
  }

  .header {
    height: 135px;
    background-image: url('//yanxuan.nosdn.127.net/5905098f74e04c39fa5e76ebb9ff591b.png');
    display: flex;
    justify-content: center;

    .core {
      display: flex;
      justify-content: space-around;
      align-self: center;

      img {
        vertical-align: middle;
        width: 71px;
        height: 71px;
        border-radius: 50%;
        margin-right: 30px;
      }

      p {
        font-size: 18px;
        color: #fff;
        overflow: hidden;
        line-height: 70px;
      }
    }
  }

  .myasset {
    box-sizing: border-box;
    background-color: #fff;
    padding-top: 10px;

    .title {
      border-bottom: 1px solid #d9d9d9;
      margin-left: 15px;
      font-size: 14px;
      text-align: left;
      line-height: 1.04rem;
    }

    .asset {
      display: flex;
      justify-content: space-between;
      font-size: 12px;

      .assetItem {
        position: relative;
        padding-top: 0.32rem;
        height: 1.6rem;
        width: 80px;
        text-align: center;

        span {
          color: #333;
          font-size: 18px;
          font-weight: 700;
        }
      }
    }
  }

  .table {
    display: flex;
    margin-top: 10px;
    background-color: #fff;
    flex-wrap: wrap;
    margin-bottom: 0.4rem;
    overflow: auto;

    .table_item {
      border-right: 1px solid #eee;
      border-bottom: 1px solid #eee;
      width: 124.2px;
      height: 90px;
      text-align: center;
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      flex-direction: column;
      cursor: pointer;

      .core {
        align-self: center;
      }
    }
    .content {
      font-size: 12px;
      line-height: 0.34rem;
      color: #333;
      margin-top: 10px;
    }
  }

  .logout {
    margin-top: 10px;
    text-align: center;
    font-size: 14px;
    background-color: #fff;
    margin-bottom: 10px;
    height: 48px;
    line-height: 48px;
  }
}
</style>
